package com.cqc.demo;

import android.app.Activity;
import android.app.Dialog;
import android.os.Build;
import android.view.Window;
import android.view.WindowManager;

/**
 * Created by ${cqc} on 2016/9/24.
 * 设置导航栏颜色
 */
public class StatusBarUtil {

    //Activity
    public static void setSattusBarColor(Activity activity,int colorResId){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
            Window window = activity.getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(activity.getResources().getColor(colorResId));

            //设置底部导航栏颜色
            window.setNavigationBarColor(activity.getResources().getColor(colorResId));
        }
    }

    //Dialog
    public static void setSattusBarColor(Dialog dialog, int colorResId){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
            Window window = dialog.getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(dialog.getContext().getResources().getColor(colorResId));

            //设置底部导航栏颜色
            window.setNavigationBarColor(dialog.getContext().getResources().getColor(colorResId));
        }
    }
}
